import { isArray } from "lodash-es";
import { ComponentInternalInstance } from "vue";

/**
 * @description 获取节点的布局位置
 * @date 17/03/2025
 * @export
 * @param {string} selector
 * @param {ComponentInternalInstance} ins
 */
export function boundingClientRect(selector: string, ins: ComponentInternalInstance): Promise<UniApp.NodeInfo> {
  return new Promise((resolve) => {
    const query = uni.createSelectorQuery().in(ins.proxy);
    query
      .select(selector)
      .boundingClientRect((res) => {
        const dom = isArray(res) ? res[0] : res;
        resolve(dom || {});
      })
      .exec();
  });
}